Geometry এবং Path ব্যবহার করে Custom Shapes তৈরি

WPF Graphics এবং Drawing Techniques - ডব্লিউপিএফ (WPF) - Microsoft Technologies

285

Geometry এবং Path হল WPF (Windows Presentation Foundation) এর শক্তিশালী বৈশিষ্ট্য যা কাস্টম শেপ এবং গ্রাফিক্স তৈরি করতে ব্যবহৃত হয়। এই দুটি উপাদান ব্যবহার করে আপনি সৃজনশীলভাবে ভেক্টর গ্রাফিক্স, কাস্টম শেপ এবং ডিজাইন তৈরি করতে পারবেন।

Geometry কী?

Geometry WPF এর একটি বিমূর্ত ক্লাস যা বিভিন্ন ধরণের শেপ এবং পাথ (paths) তৈরি করতে ব্যবহৃত হয়। এটি মূলত দুইটি প্রধান শ্রেণী হিসাবে বিভক্ত: Shape Geometry (যেমন, RectangleGeometry, EllipseGeometry) এবং PathGeometry, যা আরো কাস্টম শেপ তৈরি করতে ব্যবহৃত হয়।

Path কী?

Path একটি UI উপাদান যা একটি Geometry ধারণ করে এবং তার ভিত্তিতে ভিজ্যুয়াল কন্ট্রোল তৈরি করে। Path ব্যবহার করে আপনি কাস্টম শেপের সীমানা (outline) বা পূর্ণ রঙিন শেপ (filled shapes) তৈরি করতে পারেন।

Path এর মাধ্যমে আপনি বিভিন্ন ধরণের জটিল শেপ যেমন সোজা লাইন, বেজিয়ার কিউব, আর্ক, এবং পলিগন তৈরি করতে পারেন।

Geometry এবং Path এর মধ্যে সম্পর্ক

  • Geometry এক বা একাধিক শেপ তৈরি করতে ব্যবহৃত হয়, যা পরে Path এ রেন্ডার করা হয়।
  • Path Geometry এর ভিজ্যুয়াল রিপ্রেজেন্টেশন হিসাবে কাজ করে, যেমন গ্রাফিক্স বা শেপ প্রদর্শন করতে।

Geometry এবং Path দিয়ে Custom Shapes তৈরি করা

এখানে একটি সহজ উদাহরণ দেওয়া হলো যেখানে Path এবং Geometry ব্যবহার করে একটি কাস্টম শেপ তৈরি করা হয়েছে। আমরা একটি পলিগন এবং একটি কাস্টম আকারের শেপ তৈরি করব।


Path এবং Geometry উদাহরণ ১: পলিগন তৈরি

MainWindow.xaml:

<Window x:Class="CustomShapeExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Geometry and Path Example" Height="350" Width="525">
    <Grid>
        <!-- Custom Polygon using Path -->
        <Path Stroke="Black" StrokeThickness="2">
            <Path.Data>
                <PolygonGeometry Points="100,10 200,50 150,150 50,150 0,50" />
            </Path.Data>
        </Path>
    </Grid>
</Window>

এখানে, PolygonGeometry ব্যবহার করে একটি পলিগন তৈরি করা হয়েছে, যার পয়েন্টগুলি একটি একাধিক কোঅর্ডিনেট দ্বারা ডিফাইন করা হয়েছে। এই পলিগনটি Path এর মাধ্যমে প্রদর্শিত হবে, এবং তার বাইরের সীমানা কালো রঙের স্ট্রোক হবে।


Path এবং Geometry উদাহরণ ২: বেজিয়ার কিউব পাথ

MainWindow.xaml:

<Window x:Class="CustomShapeExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Geometry and Path Example" Height="350" Width="525">
    <Grid>
        <!-- Custom Shape using Path and Bezier Curve -->
        <Path Stroke="DarkRed" StrokeThickness="2" Fill="LightPink">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="100,100">
                        <BezierSegment Point1="150,50" Point2="200,150" Point3="300,100" />
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>
    </Grid>
</Window>

এখানে PathGeometry এবং BezierSegment ব্যবহার করা হয়েছে, যেখানে একটি বেজিয়ার কিউব পাথ তৈরি করা হয়েছে। এই শেপটি একটি বক্ররেখা তৈরি করে যা StartPoint থেকে শুরু হয়ে বিভিন্ন পয়েন্টের মধ্য দিয়ে চলে।


Path এবং Geometry উদাহরণ ৩: আর্ক শেপ

MainWindow.xaml:

<Window x:Class="CustomShapeExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Geometry and Path Example" Height="350" Width="525">
    <Grid>
        <!-- Custom Arc using Path -->
        <Path Stroke="Green" StrokeThickness="2">
            <Path.Data>
                <ArcSegment Point="200,100" Size="100,100" RotationAngle="0" IsLargeArc="True" SweepDirection="Clockwise" />
            </Path.Data>
        </Path>
    </Grid>
</Window>

এখানে ArcSegment ব্যবহার করে একটি আর্ক শেপ তৈরি করা হয়েছে। Size, RotationAngle, IsLargeArc এবং SweepDirection এর মাধ্যমে আর্কের আকৃতি এবং রূপ নিয়ন্ত্রণ করা হয়েছে।


Path এবং Geometry উদাহরণ ৪: কাস্টম শেপ

এখানে একটি কাস্টম শেপ তৈরি করা হয়েছে যা বিভিন্ন ভেক্টর শেপের মিশ্রণ।

MainWindow.xaml:

<Window x:Class="CustomShapeExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Geometry and Path Example" Height="350" Width="525">
    <Grid>
        <!-- Custom Shape using Path and Geometry -->
        <Path Stroke="Blue" StrokeThickness="3" Fill="LightYellow">
            <Path.Data>
                <GeometryGroup>
                    <RectangleGeometry Rect="50,50,150,100" />
                    <EllipseGeometry Center="200,200" RadiusX="50" RadiusY="50" />
                </GeometryGroup>
            </Path.Data>
        </Path>
    </Grid>
</Window>

এখানে GeometryGroup ব্যবহার করে একটি কাস্টম শেপ তৈরি করা হয়েছে, যা একটি RectangleGeometry এবং একটি EllipseGeometry এর মিশ্রণ। এটি একটি শেপ তৈরি করবে যা একটি আয়তক্ষেত্র এবং একটি বৃত্ত নিয়ে গঠিত।


Geometry এবং Path এর বৈশিষ্ট্যসমূহ (Features of Geometry and Path)

  1. Path একটি ভিজ্যুয়াল উপাদান যা কাস্টম শেপ এবং জটিল পাথ রেন্ডার করে।
  2. Geometry হল বিমূর্ত ক্লাস যা বিভিন্ন ধরণের শেপ যেমন RectangleGeometry, EllipseGeometry, LineGeometry ইত্যাদি তৈরি করতে ব্যবহৃত হয়।
  3. Path কাস্টম আকৃতির শেপ তৈরি করতে বিভিন্ন ধরনের Geometry একত্রিত করতে পারে।
  4. Stroke এবং Fill এর মাধ্যমে আপনি শেপের বাইরের বর্ডার এবং ভিতরের রঙ কাস্টমাইজ করতে পারবেন।
  5. Data Binding ব্যবহার করে Path এর ভিজ্যুয়াল ডেটাকে বাইন্ড করা যায়, যা ডেটার পরিবর্তনের সাথে শেপের আকার বা রঙ পরিবর্তন করতে সাহায্য করে।

সারাংশ (Summary)

Geometry এবং Path WPF এ কাস্টম শেপ এবং ভেক্টর গ্রাফিক্স তৈরি করতে ব্যবহৃত অত্যন্ত শক্তিশালী টুলস। Geometry বিভিন্ন শেপের জন্য ডেটা প্রদান করে এবং Path সেই শেপগুলিকে ভিজ্যুয়াল উপাদান হিসেবে রেন্ডার করে। Path কন্ট্রোল ব্যবহার করে আপনি সহজেই কাস্টম শেপ, আর্ক, বেজিয়ার কিউব, পলিগন ইত্যাদি তৈরি করতে পারেন, যা আপনার অ্যাপ্লিকেশনকে আরও আকর্ষণীয় এবং ইন্টারঅ্যাকটিভ করে তোলে।

Content added By
Promotion

Are you sure to start over?

Loading...